Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getting stuck after blocked state #6552

Conversation

mojganii
Copy link
Collaborator

@mojganii mojganii commented Jul 31, 2024

The app gets stuck in a blocked state after these transitions:

  • The packet tunnel is Connected, then Airplane mode is toggled.

  • The packet tunnel is Connected, then no relay constraints are satisfied.

This problem might also occur due to other reasons that result in a blocked state. To solve this issue, we need to refresh the tunnel status after reconnecting tunnel when the block state occurs. This pull request (PR) addresses the issue.


This change is Reviewable

@mojganii mojganii requested review from buggmagnet and acb-mv July 31, 2024 12:33
Copy link

linear bot commented Jul 31, 2024

@mojganii mojganii self-assigned this Jul 31, 2024
@mojganii mojganii added bug iOS Issues related to iOS labels Jul 31, 2024
@pinkisemils
Copy link
Collaborator

If this is the right solution and it ends up getitng merged, don't forget to mark the other issue as Done too :)

@mojganii mojganii force-pushed the packet-tunnel-stuck-in-blocked-state-after-reconnecting-ios-707 branch from e909728 to 4fbdd0d Compare July 31, 2024 14:53
@mojganii mojganii force-pushed the packet-tunnel-stuck-in-blocked-state-after-reconnecting-ios-707 branch from 4fbdd0d to 7fd5d38 Compare August 7, 2024 17:44
@mojganii mojganii force-pushed the packet-tunnel-stuck-in-blocked-state-after-reconnecting-ios-707 branch 2 times, most recently from 94b36cc to 968f7a5 Compare August 8, 2024 08:09
Copy link
Contributor

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 18 of 23 files at r1, all commit messages.
Reviewable status: 18 of 23 files reviewed, 7 unresolved discussions (waiting on @mojganii)


ios/MullvadMockData/MullvadREST/RelaySelectorStub.swift line 15 at r1 (raw file):

/// Relay selector stub that accepts a block that can be used to provide custom implementation.
public final class RelaySelectorStub: RelaySelectorProtocol {
    var block: (RelayConstraints, UInt) throws -> SelectedRelays

How about we rename this selectRelaysResult


ios/MullvadVPN/TunnelManager/TunnelManager.swift line 29 at r1 (raw file):

//        switch self {
//            object.build(for theCase)
//        }

Let's remove these comments


ios/MullvadVPN/TunnelManager/TunnelManager.swift line 100 at r1 (raw file):

//    #else
//    internal var MappingOperation = MapConnectionStatusOperation.self
//    #endif

These too


ios/MullvadVPN/TunnelManager/TunnelManager.swift line 940 at r1 (raw file):

//            queue: internalQueue,
//            interactor: TunnelInteractorProxy(self),
//            connectionStatus: connectionStatus,

And these as well


ios/MullvadVPNTests/MullvadVPN/TunnelManager/TunnelManagerTests.swift line 122 at r1 (raw file):

    }

    func testExitBlockedStateAfterSatisfyingConstraints() async throws {

We can add a comment describing what the test does since the setup is quite complicated.
We could say something along the lines of


ios/MullvadVPNTests/MullvadVPN/TunnelManager/TunnelManagerTests.swift line 181 at r1 (raw file):

        await fulfillment(
            of: [blockedExpectation, connectedExpectation],
            timeout: .UnitTest.timeout

We want to make sure that the expectations are met in order here.

        await fulfillment(
            of: [blockedExpectation, connectedExpectation],
            timeout: .UnitTest.timeout,
            enforceOrder: true
        )

ios/PacketTunnelCore/Actor/PacketTunnelActor.swift line 287 at r1 (raw file):

        reason: ActorReconnectReason
    ) async throws {
        defer {

We should leave this after the call to stopDefaultPathObserver
Otherwise, this will be ran here even if obfuscateConnection throws an error (For example, invalid constraints in the relay selector) which is not a desired behaviour.

@mojganii mojganii force-pushed the packet-tunnel-stuck-in-blocked-state-after-reconnecting-ios-707 branch 3 times, most recently from 599eb5c to aad9489 Compare August 9, 2024 11:54
Copy link
Contributor

@rablador rablador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 16 of 23 files at r1, 5 of 5 files at r2, 2 of 2 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: all files reviewed, 12 unresolved discussions (waiting on @mojganii)


ios/MullvadRESTTests/TransportStrategyTests.swift line 9 at r3 (raw file):

//

@testable import MullvadMockData

Intentional import?


ios/MullvadVPN/TunnelManager/MapConnectionStatusOperation.swift line 25 at r3 (raw file):

    private let logger = Logger(label: "TunnelManager.MapConnectionStatusOperation")

    required init(

Is this change necessary?


ios/MullvadVPN/TunnelManager/SendTunnelProviderMessageOperation.swift line 63 at r3 (raw file):

        addObserver(
            BackgroundObserver(
                application: backgroundTaskProvider,

"application" should probably be renamed to "backgroundTaskProvider".


ios/MullvadVPN/TunnelManager/TunnelInteractor.swift line 19 at r3 (raw file):

    var tunnel: (any TunnelProtocol)? { get }
    var application: any BackgroundTaskProvider { get }

There is this and other places in the code where "application" hasn't been renamed to the match the new type.


ios/MullvadMockData/MullvadREST/AccessMethodRepository+Stub.swift line 12 at r4 (raw file):

import MullvadSettings

public struct AccessMethodRepositoryStub: AccessMethodRepositoryDataSource {

Do we need to make all these public?

Copy link
Contributor

@acb-mv acb-mv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 5 of 23 files at r1, all commit messages.
Reviewable status: all files reviewed, 12 unresolved discussions (waiting on @mojganii)

Copy link
Contributor

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 23 files at r1, 5 of 5 files at r2, 2 of 2 files at r3, 1 of 1 files at r4, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @mojganii)

@mojganii mojganii force-pushed the packet-tunnel-stuck-in-blocked-state-after-reconnecting-ios-707 branch from aad9489 to d69d97c Compare August 12, 2024 16:16
Copy link
Collaborator Author

@mojganii mojganii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 18 of 27 files reviewed, 5 unresolved discussions (waiting on @buggmagnet and @rablador)


ios/MullvadMockData/MullvadREST/RelaySelectorStub.swift line 15 at r1 (raw file):

Previously, buggmagnet wrote…

How about we rename this selectRelaysResult

Done.


ios/MullvadRESTTests/TransportStrategyTests.swift line 9 at r3 (raw file):

Previously, rablador (Jon Petersson) wrote…

Intentional import?

AccessMethodRepositoryStub was moved to MullvadMockData .


ios/MullvadVPN/TunnelManager/MapConnectionStatusOperation.swift line 25 at r3 (raw file):

Previously, rablador (Jon Petersson) wrote…

Is this change necessary?

Which one is drawing your attention? I didn't get the difference.


ios/MullvadVPN/TunnelManager/SendTunnelProviderMessageOperation.swift line 63 at r3 (raw file):

Previously, rablador (Jon Petersson) wrote…

"application" should probably be renamed to "backgroundTaskProvider".

Done.


ios/MullvadVPN/TunnelManager/TunnelInteractor.swift line 19 at r3 (raw file):

Previously, rablador (Jon Petersson) wrote…

There is this and other places in the code where "application" hasn't been renamed to the match the new type.

Done.


ios/MullvadVPN/TunnelManager/TunnelManager.swift line 29 at r1 (raw file):

Previously, buggmagnet wrote…

Let's remove these comments

Done.


ios/MullvadVPN/TunnelManager/TunnelManager.swift line 100 at r1 (raw file):

Previously, buggmagnet wrote…

These too

Done.


ios/MullvadVPN/TunnelManager/TunnelManager.swift line 940 at r1 (raw file):

Previously, buggmagnet wrote…

And these as well

Done.


ios/MullvadVPNTests/MullvadVPN/TunnelManager/TunnelManagerTests.swift line 122 at r1 (raw file):

Previously, buggmagnet wrote…

We can add a comment describing what the test does since the setup is quite complicated.
We could say something along the lines of

Done.


ios/MullvadVPNTests/MullvadVPN/TunnelManager/TunnelManagerTests.swift line 181 at r1 (raw file):

Previously, buggmagnet wrote…

We want to make sure that the expectations are met in order here.

        await fulfillment(
            of: [blockedExpectation, connectedExpectation],
            timeout: .UnitTest.timeout,
            enforceOrder: true
        )

Done.


ios/PacketTunnelCore/Actor/PacketTunnelActor.swift line 287 at r1 (raw file):

Previously, buggmagnet wrote…

We should leave this after the call to stopDefaultPathObserver
Otherwise, this will be ran here even if obfuscateConnection throws an error (For example, invalid constraints in the relay selector) which is not a desired behaviour.

Done.


ios/MullvadMockData/MullvadREST/AccessMethodRepository+Stub.swift line 12 at r4 (raw file):

Previously, rablador (Jon Petersson) wrote…

Do we need to make all these public?

Yes, wea re using that in TunnelManagerTests.

Copy link
Contributor

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 9 of 9 files at r5, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @rablador)

@mojganii mojganii force-pushed the packet-tunnel-stuck-in-blocked-state-after-reconnecting-ios-707 branch from d69d97c to 85acb9e Compare August 13, 2024 09:50
@buggmagnet buggmagnet dismissed rablador’s stale review August 13, 2024 09:54

Reviewer actually agreed.

Copy link
Contributor

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 5 of 5 files at r6, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @rablador)

@buggmagnet buggmagnet merged commit bf9d513 into main Aug 13, 2024
8 of 9 checks passed
@buggmagnet buggmagnet deleted the packet-tunnel-stuck-in-blocked-state-after-reconnecting-ios-707 branch August 13, 2024 09:56
Copy link

🚨 End to end tests failed. Please check the failed workflow run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug iOS Issues related to iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants